package com.wcl.demo.ui.adapter;

import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wcl.demo.R;
import com.wcl.demo.ui.fragment.ItemInterface.AddClickItemListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by dllo on 15/11/27.
 */
public class AddClickInforAdapter extends RecyclerView.Adapter<AddClickInforAdapter.AddClickInforAdapterViewHolder> {
    private int[] imgs = {R.mipmap.iconfont_files, R.mipmap.iconfont_xiangjis,
            R.mipmap.iconfont_tupians, R.mipmap.iconfont_weizhis,R.mipmap.iconfont_mycard};
    private AddClickItemListener listener;

    public AddClickInforAdapter(){
        notifyDataSetChanged();
    }
    public void setAddItemClick(AddClickItemListener listener) {
        this.listener = listener;
    }

    class AddClickInforAdapterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private ImageView jiahao_detail;
        private int position;

        public AddClickInforAdapterViewHolder(View itemView) {
            super(itemView);
            jiahao_detail = (ImageView) itemView.findViewById(R.id.jiahao_detail);
            jiahao_detail.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (imgs.length > 0) {
                int img = imgs[position];
                if (listener != null) {
                    listener.setAddClickItemClickListener(img);
                }
            }
        }
    }

    @Override
    public AddClickInforAdapterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.activity_recyclerview_jiahao, null);

        return new AddClickInforAdapterViewHolder(view);
    }

    @Override
    public void onBindViewHolder(AddClickInforAdapterViewHolder holder, int position) {
        holder.jiahao_detail.setImageResource(imgs[position]);
        holder.position = position;
    }

    @Override
    public int getItemCount() {
        return imgs != null && imgs.length > 0 ? imgs.length : 0;
    }
}
